package com.slipper.system.codeless.controller;

import com.slipper.constants.Constants;
import com.slipper.system.codeless.bo.VisualTemplateBO;
import com.slipper.system.codeless.service.VisualTemplateService;
import com.slipper.util.ResultUtil;
import com.slipper.util.Tool;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/system/visualTemplate")
public class VisualTemplateController {
    @Resource
    private VisualTemplateService visualTemplateService;
    
    @PostMapping(value = "/queryBy")
    public String queryBy(@RequestBody VisualTemplateBO bo) {
        if(Tool.isBlank(bo.getId())) {
            return ResultUtil.failureResult("数据获取失败！");
        }
        return ResultUtil.successResult(visualTemplateService.queryBy(bo.getId()));
    }

    @PostMapping(value = "/queryList")
    public String queryList(@RequestBody VisualTemplateBO bo) {
        return ResultUtil.successResult(visualTemplateService.queryList(bo));
    }

    @PostMapping(value = "/queryCategoryPage")
    public String queryCategoryPage(@RequestBody VisualTemplateBO bo) {
        return ResultUtil.successResult(visualTemplateService.queryCategoryPage(bo));
    }
    
    @PostMapping(value = "/queryPage")
    public String queryPage(@RequestBody VisualTemplateBO bo) {
        return ResultUtil.successResult(visualTemplateService.queryPage(bo));
    }

    @PostMapping(value = "/save")
    public String save(@RequestBody VisualTemplateBO bo) {
        bo.setOperateId(Constants.getCurrentUser().getEmployeeId());
        return ResultUtil.saveResult(visualTemplateService.save(bo), bo);
    }

    @PostMapping(value = "/saveSimple")
    public String saveSimple(@RequestBody VisualTemplateBO bo) {
        bo.setOperateId(Constants.getCurrentUser().getEmployeeId());
        return ResultUtil.saveResult(visualTemplateService.saveSimple(bo), bo);
    }

    @PostMapping(value = "/delete")
    public String delete(@RequestBody VisualTemplateBO bo) {
        return ResultUtil.deleteResult(visualTemplateService.delete(bo));
    }
}
